<?php
	echo $javascript->link('prototype.js');
	 echo $javascript->codeBlock('function updatePostList(topico_id) {
			new Ajax.Updater("postsIndex","/mastergoal-uca/Mastergoal/posts/index/"+topico_id, {asynchronous:true, evalScripts:true, requestHeaders:["X-Update", "postsIndex"]});
		}'
	);

;?>
<div id="postsIndex">
<?php echo "Topico: ".$topico['titulo'] ?>
<h2><?php __('Posts');?></h2>

<table cellpadding="0" cellspacing="0">
<tr>
	<th><?php echo 'Post';?></th>
	<th><?php echo 'Texto';?></th>
	<?php if($grupo_id == 1){ //cuando es administrador sale las acciones edit y delete
		echo '<th class="actions"><?php __(\'Acciones\');?></th>';
	}?>
</tr>
<?php
$i = 0;
foreach ($posts as $post):
	$class = null;
	if ($i++ % 2 == 0) {
		$class = ' class="altrow"';
	}
?>
	<tr<?php echo $class;?>>
		<td>
			<?php echo "Numero: ".$post['Post']['post']; ?><br>
			<?php echo "Escrito por: ".$post['User']['username']; ?><br>
			<?php echo "Fecha creada:".$post['Post']['fecha']; ?>
		</td>
		<td>
			<?php echo $post['Post']['texto']; ?>
		</td>
		<?php if($grupo_id == 1){ //que solo el administrador pueda modificar el post o borrar
			echo '<td class="actions">';
				echo $html->link(__('Edit', true), array('action'=>'edit', $post['Post']['post'],$topico['topico'])); 
				echo $html->link(__('Delete', true), array('action'=>'delete', $post['Post']['post'],$topico['topico']), null, sprintf(__('Are you sure you want to delete # %s?', true), $post['Post']['post']));
			echo '</td>';
		}?>
	</tr>
<?php endforeach; ?>
</table>
<div id="newcomment"></div>
<div class="actions">
	<ul>
		<li><?php echo $html->link(__('Lista de Topicos', true), array('controller' => 'topicos','action'=>'index',$topico['tema_id'])); ?></li>
		<li><?php if($grupo_id ==3 || $grupo_id ==2|| $grupo_id ==1){ //A partir del Trial puede agregar posts
			//echo $html->link(__('Nuevo Post', true), array('controller' =>'posts','action'=>'add', $topico['topico']));
			echo $ajax->link(__('Nuevo Post', true), 'add/' . $topico['topico'], array('update' => 'newcomment'));
			}?></li>
	</ul>
</div>
</div>


